package cn.org.tpeach.nosql.redis.service;

import cn.org.tpeach.nosql.bean.PageBean;
import cn.org.tpeach.nosql.enums.RedisTreeType;
import cn.org.tpeach.nosql.redis.bean.*;
import io.lettuce.core.KeyScanCursor;
import io.lettuce.core.ScanCursor;

import java.util.List;
import java.util.Map;

/**
 * @author tyz
 * @Title: RedisConnectService
 * @ProjectName RedisLark
 * @Description: TODO
 * @date 2020-05-25 22:47
 * @since 2.0.0
 */
public interface IRedisConnectService {

    String ping(String id);

    boolean connectTest(RedisConnectInfo connectInfo) ;

    Long getDbKeySize(String id, int db,boolean printLog);

    Long getDbKeySize(String id, int db);
    /**
     * @param id
     * @param db
     * @param key
     * @param seconds
     * @return
     */
    Boolean expireKey(String id, int db, byte[] key, int seconds);
    /**
     * 获取数据库数量
     *
     * @param id
     * @return
     */
    List<DbAmount> getDbAmountAndSize(String id);


    /**
     *
     * @param id
     * @param db
     * @param totalPattren 是否需要匹配的总数量 效率会有影响
     * @return
     */
    KeyScanCursor<byte[]> getKeys(String id, int db, String pattern, boolean totalPattren );

    String flushDb(String id, int db);

    RedisKeyInfo addSingleKeyInfo(RedisKeyInfo keyInfo);

    Long deleteKeys(String id, int dbIndex, byte[]... key);

    Long deleteKeys(String id, int db, String pattern,Integer totalCount);

    Boolean remamenx(String id, int db,final byte[] oldkey, final byte[] newkey);

    /**
     *
     * @param id
     * @param db
     * @param key
     * @param pattern
     * @param pageBean
     * @param cursor 当前游标 第一页时使用初始化游标
     * @param srcKeyInfo 为空时将ttl等信息进行刷新
     * @return
     */
    RedisKeyInfo getKeyInfo(String id, int db, byte[] key, String pattern, PageBean pageBean, ScanCursor cursor, RedisKeyInfo srcKeyInfo);

    int deleteRowKeyInfo(String id, int db, byte[] key, RedisTreeType type, List<RedisKeyData> redisKeyDataList);

    RedisKeyInfo updateKeyInfo(RedisKeyInfo newKeyInfo, RedisKeyInfo oldKeyInfo);

    Long addRowKeyInfo(RedisKeyInfo keyInfo,boolean isLeftList);

    Map<String,String> getConnectInfo(String id, boolean isFresh, boolean printLog);

    Map<String,String> getConnectInfo(String id,boolean isFresh );

    List<RedisClientBo> clientList(String id);

    List<SlowLogBo>  slowlogGet(String id);

    List<RedisClientBo> clientList(String id, boolean printLog);

    List<SlowLogBo> slowlogGet(String id, boolean printLog);
}